<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>系统用户管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>

    <div style="padding-bottom: 5px;">

        <div class="uc-toolbaroverflow" _borderStyle="border-top:0;">

            <span>姓名：</span>
            <input  id="queryName" name="queryName" class="mini-textbox"  />

            <span class="separator"></span>
            <span>手机号：</span>
            <input  id="queryMobile" name="queryMobile" class="mini-textbox"  />

            <span class="separator"></span>
            <span>部门：</span>
            <input id="queryDepartmentId" name="queryDepartmentId" class="mini-treeselect" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
                   virtualScroll="true"  required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择部门"/>




            <span class="separator"></span>
            <span>在职状态：</span>
            <input id="queryWorkingState" name="queryDepartmentId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                   required="false" allowInput="false" showNullItem="true" nullItemText="请选择..."/>

            <span class="separator"></span>
            <span>锁定状态：</span>
            <input id="queryIsLock" name="queryIsLock" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                   required="false" allowInput="false" showNullItem="true" nullItemText="请选择..."/>


            <span class="separator"></span>

            <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>

            <div style="margin-top: 4px"></div>

            <a class="mini-button" iconCls="icon-add" onclick="addSystemUser()">增加</a>

            <span class="separator"></span>

            <a class="mini-button" iconCls="icon-edit" onclick="updateSystemUser()">修改</a>


            <span class="separator"></span>

            <a class="mini-button" iconCls="icon-edit" onclick="resetSystemUserPassword()">重设密码</a>


        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/systemmaintain/sys_user/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="true">
            <div property="columns">
                <div field="id" width="140" headerAlign="center" align="left" allowSort="true">ID</div>
                <div field="workingState" width="100" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">是否在职</div>
                <div field="isLock" width="100" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">是否锁定</div>
                <div field="name" width="100" headerAlign="center" align="center" allowSort="true">姓名</div>
                <div field="fullPinyin" width="100" headerAlign="center" align="center" allowSort="true">全拼</div>
                <div field="camelCharPinyin" width="100" headerAlign="center" align="center" allowSort="true">简拼</div>
                <div field="mobile" width="100" headerAlign="center" align="center" allowSort="true">手机号</div>
                <div field="idCard" width="200" headerAlign="center" align="center" allowSort="true">身份证号</div>
                <div field="genderId" width="100" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">性别</div>
                <div field="departmentId" width="100" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"department"}' renderer="commonRender">部门</div>
                <div field="address" width="150" headerAlign="center" align="center" allowSort="true">地址</div>
                <div field="email" width="200" headerAlign="center" align="center" allowSort="true">电子邮箱</div>
                <div field="qq" width="100" headerAlign="center" align="center" allowSort="true">QQ号</div>
                <div field="wx" width="100" headerAlign="center" align="center" allowSort="true">微信号</div>
                <div field="registerDate" width="100" headerAlign="center" align="center" allowSort="true">入职日期</div>
                <div field="leaveDate" width="100" headerAlign="center" align="center" allowSort="true">离职日期</div>
                <div field="comment" width="150" headerAlign="center" align="left" allowSort="true">备注</div>
                <div field="createTime" width="100" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss" allowSort="true" sortOrder="desc" renderer="ondayRenderer">创建时间</div>
                <div field="createUserId" width="80" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建人</div>
            </div>
        </div>
    </div>


    <!-- 系统用户信息添加与更新面板 -->
    <div id="systemUserPanel" class="mini-window" title="系统用户管理" style="width:800px;height:650px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="updateAndSaveBtn" name="updateAndSaveBtn" class="mini-button" iconCls="icon-save" onclick="updateAndSave()">保存</a>
            <a  id="addAndSaveBtn" name="addAndSaveBtn" class="mini-button" iconCls="icon-save" onclick="addAndSave()">保存</a>
        </div>

        <div id="systemUserForm">

            <table style="width: 100%">
                <tr>
                    <td><label>ID:</label></td>
                    <td colspan="3"><input id="id" name="id"  class="mini-textbox" readonly="readonly"/><span style="color:red">添加系统用户时不用填写!</span></td>
                </tr>

                <tr>
                    <td><label>姓名:</label></td>
                    <td><input id="name" name="name"  class="mini-textbox" required="true" onvaluechanged="getPinyin" requiredErrorText="姓名不能为空"/></td>
                    <td><label>性别:</label></td>
                    <td>
                        <input id="genderId" name="genderId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                               required="true" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择性别"/>
                    </td>
                </tr>

                <tr>
                    <td><label>全拼:</label></td>
                    <td><input id="fullPinyin" name="fullPinyin"  class="mini-textbox" required="true" requiredErrorText="全拼不能为空"/></td>
                    <td><label>简拼:</label></td>
                    <td><input id="camelCharPinyin" name="camelCharPinyin"  class="mini-textbox" required="true" requiredErrorText="简拼不能为空"/></td>
                </tr>


                <tr id="passwordArea">
                    <td><label>密码:</label></td>
                    <td><input id="password" name="password"  class="mini-password" required="true"  requiredErrorText="密码不能为空"/></td>
                    <td><label>确认密码:</label></td>
                    <td><input id="confirmPassword" name="confirmPassword"  class="mini-password" required="true"  onvaluechanged="confirmPwd1" requiredErrorText="确认密码不能为空"/></td>
                </tr>

                <tr>
                    <td><label>手机号:</label></td>
                    <td><input id="mobile" name="mobile"  class="mini-textbox" required="true" requiredErrorText="手机号不能为空"/></td>
                    <td><label>身份证号:</label></td>
                    <td><input id="idCard" name="idCard"  class="mini-textbox" required="true" requiredErrorText="身份证号不能为空"/></td>
                </tr>

                <tr>
                    <td><label>地址:</label></td>
                    <td colspan="3"><input id="address" name="address"  class="mini-textbox"  style="width: 80%"/></td>
                </tr>

                <tr>
                    <td><label>是否在职:</label></td>
                    <td>
                        <input id="workingState" name="workingState" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                               required="true" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择在职状态"/>
                    </td>
                    <td><label>是否锁定:</label></td>
                    <td>
                        <input id="isLock" name="isLock" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                               required="true" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择锁定状态"/>
                    </td>
                </tr>

                <tr>
                    <td><label>部门:</label></td>
                    <td>
                        <input id="departmentId" name="departmentId" class="mini-treeselect" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
                               virtualScroll="true"  required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择部门"/>

                    </td>
                    <td><label>电子邮箱:</label></td>
                    <td><input id="email" name="email"  class="mini-textbox" required="false" requiredErrorText="电子邮箱不能为空"/></td>
                </tr>

                <tr>
                    <td><label>QQ号:</label></td>
                    <td><input id="qq" name="qq"  class="mini-textbox" required="false" requiredErrorText="QQ号不能为空"/></td>
                    <td><label>微信号:</label></td>
                    <td><input id="wx" name="wx"  class="mini-textbox" required="false" requiredErrorText="微信号不能为空"/></td>
                </tr>


                <tr>
                    <td><label>入职日期:</label></td>
                    <td>
                        <input id="registerDate" name="registerDate"  class="mini-datepicker" format="yyyyMMdd" allowInput="false" required="false" requiredErrorText="入职日期不能为空"/>
                    </td>
                    <td><label>离职日期:</label></td>
                    <td>
                        <input id="leaveDate" name="leaveDate"  class="mini-datepicker" format="yyyyMMdd" allowInput="false" required="false" requiredErrorText="入职日期不能为空"/>
                    </td>
                </tr>

                <tr>
                    <td><label>备注:</label></td>
                    <td colspan="3"><input id="comment"  name="comment" style="width:80%;height:100px;text-align: left;" class="mini-textarea"   emptyText="请输入备注信息" /></td>
                </tr>
            </table>

        </div>
    </div>



    <!-- 密码修改面板 -->
    <div id="systemUserUpdatePasswordPanel" class="mini-window" title="密码修改" style="width:400px;height:300px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
    >
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="savePasswordBtn" name="savePasswordBtn" class="mini-button" iconCls="icon-save" onclick="updatePassword()">保存新密码</a>
        </div>

        <div id="systemUserUpdatePasswordForm">

            <table style="width: 100%">
                <tr>
                    <td><label>ID:</label></td>
                    <td><input id="userId" name="userId"  class="mini-textbox" readonly="readonly"/></td>
                </tr>

                <tr>
                    <td><label>姓名:</label></td>
                    <td colspan="3"><input id="userName" name="userName"  class="mini-textbox" required="true"  requiredErrorText="姓名不能为空" readonly="readonly"/></td>
                </tr>

                <tr >
                    <td><label>密码:</label></td>
                    <td><input id="newPassword" name="newPassword"  class="mini-password" required="true"  requiredErrorText="密码不能为空"/></td>
                </tr>

                <tr >
                    <td><label>确认密码:</label></td>
                    <td><input id="confirmNewPassword" name="confirmNewPassword"  class="mini-password" required="true"  onvaluechanged="confirmPwd2" requiredErrorText="确认密码不能为空"/></td>
                </tr>


            </table>

        </div>
    </div>


    <script type="text/javascript">
        mini.parse();

        let queryName = mini.get("queryName");
        let queryMobile = mini.get("queryMobile");
        let queryDepartmentId = mini.get("queryDepartmentId");
        let queryWorkingState = mini.get("queryWorkingState");
        let queryIsLock = mini.get("queryIsLock");


        let genderId = mini.get("genderId");
        let workingState = mini.get("workingState");
        let isLock = mini.get("isLock");
        let departmentId = mini.get("departmentId");


        let grid = mini.get("datagrid1");

        let form = new mini.Form("#systemUserForm");
        let systemUserUpdatePasswordForm = new mini.Form("#systemUserUpdatePasswordForm");

        let systemUserPanel = mini.get("systemUserPanel");
        let systemUserUpdatePasswordPanel = mini.get("systemUserUpdatePasswordPanel");


        let updateAndSaveBtn = mini.get("updateAndSaveBtn");
        let addAndSaveBtn = mini.get("addAndSaveBtn");



        $(function () {

            let jsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_YES_NO");
            queryWorkingState.load(jsonData);
            queryIsLock.load(jsonData);
            workingState.load(jsonData);
            isLock.load(jsonData);

            jsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_GENDER");
            genderId.load(jsonData);

            let depJsonData=commonRenderDropList("department");
            queryDepartmentId.loadList(depJsonData, "id", "pid");
            departmentId.loadList(depJsonData, "id", "pid");

            // 加载列表数据
            grid.load();

        });

        function search() {

            let name = queryName.getValue();
            let mobile = queryMobile.getValue();
            let departmentId = queryDepartmentId.getValue();
            let workingState = queryWorkingState.getValue();
            let isLock = queryIsLock.getValue();

            grid.load({
                name:name,
                mobile:mobile,
                departmentId:departmentId,
                workingState:workingState,
                isLock:isLock
            });
        }

        function deleteSystemUser() {

            let row = grid.getSelected();
            if(!row){
                mini.alert("请选择要删除的行!","系统用户删除",null);
                return;
            }

            if(confirm("确定要删除选择的车辆？删除后不可恢复!"))
            {
                let ret = public_getServerData("${base}/pages/systemmaintain/sys_user/delete",{id:row.id});
                if(ret.ok) {
                    public_showTip(ret);
                    // 重新刷新数据
                    grid.reload();
                }
            }
        }

        function addSystemUser() {
            form.clear();
            addAndSaveBtn.show();
            updateAndSaveBtn.hide();
            public_showModelAtPos("systemUserPanel", "center", "middle");
        }

        function addAndSave() {
            // 添加并保存
            form.validate();
            if (form.isValid() == false) return;
            let data = form.getData(true);

            let ret = public_getServerData("${base}/pages/systemmaintain/sys_user/insert",data);
            if(ret.ok) {
                public_showTip(ret);

                // 重新刷新数据
                grid.reload();
                public_onCancel('systemUserPanel');


            }
        }

        function updateSystemUser() {

            form.clear();
            // 获取当前选中的行
            let row = grid.getSelected();

            if(!row){
                mini.alert("请选择要编辑的行!","系统用户编辑",null);
                return;
            }

            if(row.registerDate){
                row.registerDate=public_parseNumberToDate(row.registerDate);
            }

            if(row.leaveDate){
                row.leaveDate=public_parseNumberToDate(row.leaveDate);
            }

            form.setData(row);

            addAndSaveBtn.hide();
            updateAndSaveBtn.show();



            $("#passwordArea").hide();

            // 显示编辑面板
            public_showModelAtPos("systemUserPanel", "center", "middle");
        }

        function updateAndSave() {
            form.validate();
            if (form.isValid() == false) return;
            let data = form.getData(true);

            let ret = public_getServerData("${base}/pages/systemmaintain/sys_user/update",data);
            if(ret.ok) {
                public_showTip(ret);

                // 重新刷新数据
                grid.reload();
                public_onCancel('systemUserPanel');

            }
        }


        let fullPinyin = mini.get("fullPinyin");
        let camelCharPinyin = mini.get("camelCharPinyin");

        function getPinyin(e) {
            if(e.value!=""){
                fullPinyin.setValue(pinyin.getFullChars(e.value));
                camelCharPinyin.setValue(pinyin.getCamelChars(e.value));
            }
            else{
                fullPinyin.setValue("");
                camelCharPinyin.setValue("");
            }
        }


        function resetSystemUserPassword() {

            // 获取当前选中的行
            let row = grid.getSelected();


            if(!row){
                mini.alert("请选择要重设置用户密码的行!","系统用户密码重设",null);
                return;
            }

            let userId = mini.get("userId");
            let userName = mini.get("userName");

            userId.setValue(row.id);
            userName.setValue(row.name);

            // 显示编辑面板
            public_showModelAtPos("systemUserUpdatePasswordPanel", "center", "middle");

        }


        function updatePassword() {

            if(!confirmPwd2()){
                return;
            }

            systemUserUpdatePasswordForm.validate();
            if (systemUserUpdatePasswordForm.isValid() == false) return;

            let data = systemUserUpdatePasswordForm.getData(true);


            let ret = public_getServerData("${base}/pages/systemmaintain/sys_user/resetPassword?id=" + data.userId + "&password=" + data.confirmNewPassword);
            if(ret.ok) {
                public_showTip(ret);

                public_onCancel('systemUserUpdatePasswordPanel');

            }

        }


        let password = mini.get("password");
        let confirmPassword = mini.get("confirmPassword");


        function confirmPwd1() {
            let pwd1=password.getValue();
            let pwd2=confirmPassword.getValue();
            if(pwd1!=pwd2){
                mini.alert("两次输入的密码不一致！","密码校验提示");
                password.setValue("");
                confirmPassword.setValue("");
                password.setIsValid(false);
                return false;
            }
            return true;
        }


        let newPassword = mini.get("newPassword");
        let confirmNewPassword = mini.get("confirmNewPassword");
        function confirmPwd2() {
            let pwd1=newPassword.getValue();
            let pwd2=confirmNewPassword.getValue();
            if(pwd1!=pwd2){
                mini.alert("两次输入的密码不一致！","密码校验提示");
                newPassword.setValue("");
                confirmNewPassword.setValue("");
                newPassword.setIsValid(false);
                return false;
            }
            return  true;
        }



    </script>
</body>
</html>